"""
@name : 5.保留元数据
@author : wenyao
@projectname: sanchuanglianxi
"""
#元数据
#元数据 又称中介数据，中继数据。一般都是描述数据的数据，比如函数的名字，文档字符串，注解。
import time
import logging
import functools
from functools import wraps

def cost(func):  #func --> _log
    print("this is cost")
    def _cost(*args):
        start = time.time()
        print("start .........")
        rest = func(*args)
        print(func.__name__)
        end = time.time()
        print("cost:",end-start)
        return rest
    return _cost

logger = logging.getLogger()
fh = logging.FileHandler('func.log')
ch = logging.StreamHandler()
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s %(message)s")
fh.setFormatter(formatter)
logger.addHandler(fh)
logger.addHandler(ch)
logger.setLevel(logging.DEBUG)
def logger1(func):
        #@functools.wraps(func)
        @wraps(func)
        #将func的元数据复制给_log
        #保留元数据
        def _log(*args):
            logger.setLevel(logging.DEBUG)
            theresult = func(*args)
            print("执行了函数")
            # logger.debug('执行了%s函数'%func.__name__)
            return theresult

        return _log

#@cost
@logger1
# func1 = logger1(func1)
def func1():
    print("i am func1")

print(func1.__name__)